package com.ixuestar.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.krysalis.barcode4j.impl.code39.Code39Bean;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import org.krysalis.barcode4j.tools.UnitConv;

import com.ixuestar.entity.SchoolStudent;

public class BarCodeUtil {
	
	@SuppressWarnings("resource")
	public static void getBarCode0(String msg,String path,String fileName){
        try {
        	//查看文件夹是否存在 如果不存在就创建
    		File file0 = new File(path);
    		if (!file0.exists()) {
    			file0.mkdirs();
    		}
    		//定义文件路径
    		String filePath = path + "\\" + fileName;
            OutputStream ous=new FileOutputStream(filePath);
            if(StringUtils.isEmpty(msg) || ous==null)
                return ;
            //选择条形码类型(好多类型可供选择)
//            Code128Bean bean=new Code128Bean();
            Code39Bean bean = new Code39Bean();
            //设置长宽
            final double moduleWidth=0.3;
            final int resolution=200;
            bean.setModuleWidth(moduleWidth);
            bean.doQuietZone(true);
            bean.setWideFactor(2);
            String format = "image/png";
            // 输出流
            BitmapCanvasProvider canvas = new BitmapCanvasProvider(ous, format,
                resolution, BufferedImage.TYPE_BYTE_BINARY, false, 0);
            //生成条码
            bean.generateBarcode(canvas,msg);
            canvas.finish();
        }catch (IOException e) {
            throw new RuntimeException(e);
        }
 
    }
	
	@SuppressWarnings("resource")
	public static void getBarCode1(String msg,String path,String fileName){
		//查看文件夹是否存在 如果不存在就创建
		File file0 = new File(path);
		if (!file0.exists()) {
			file0.mkdirs();
		}
		//定义文件路径
		String filePath = path + "\\" + fileName;
		//定义其他属性
        int height = 100;
		double width = UnitConv.in2mm(1.2f / height);
		File file = new File(filePath);
		OutputStream out;
		try {
			out = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			throw new RuntimeException(e);
		}
		Code39Bean c39 = new Code39Bean();
//		Code128Bean c39 = new Code128Bean();
		// 设置属性
		c39.setModuleWidth(width);
		c39.setWideFactor(2);
		String format = "image/png";
		BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, format, height, BufferedImage.TYPE_BYTE_BINARY,false, 0);
		// 生成图片
		c39.generateBarcode(canvas, msg);
		try {
			// 关闭流
			canvas.finish();
			System.out.println("ok...");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
 
    }
	
	
	
	public static void main(String[] args) {
		
		List<Object> list1 = new LinkedList<>();
		List<Object> list2 = new LinkedList<>();
		
		SchoolStudent schoolStudent = new SchoolStudent();
		schoolStudent.setIxscId("001");
		schoolStudent.setIxssName("张三");
		list1.add(schoolStudent);
		SchoolStudent schoolStudent1 = new SchoolStudent();
		schoolStudent1.setIxscId("002");
		schoolStudent1.setIxssName("李四");
		list1.add(schoolStudent1);
		list2.add(schoolStudent1);
		
		for (int i = 0; i < list2.size(); i++) {
			Object object = list2.get(i);
			list1.remove(object);
		}
//		System.out.println(list1);
//		System.out.println(list2);
//		list1.removeAll(list2);
		System.out.println(list1);
		
	}
}
